
package com.work.mvc.view.window;

import com.vaadin.shared.ui.AlignmentInfo.Bits;
import com.vaadin.ui.*;
import com.vaadin.ui.themes.Reindeer;
import com.work.constants.view.ComponentsSize;
import com.work.db.entity.WorkDay;
import com.work.i18n.Messages;
import com.work.mvc.*;
import com.work.mvc.controler.*;
import com.work.mvc.view.form.WorkDayForm;
import com.work.util.*;

public class WorkTimeWindowView extends Window implements View {

	private static final long serialVersionUID = -3161631057860352299L;

	private WorkTimeWindowController controller = new WorkTimeWindowController(this);
	
	private WorkDay workDay;
	
	public WorkTimeWindowView(WorkDay workDay, MonthWorkTimeTableController monthWorkTimeTableController)
	{
		this.workDay = workDay;
		controller.setParentComponentController(monthWorkTimeTableController);
		init();
	}

	@Override
	public void init()
	{
		this.setCaption(AppConstants.TEXT_EDIT_OF_WORKTIME + ": " + AppUtils.formatDate(workDay.getDate()));
		this.setModal(true);
		this.setStyleName(Reindeer.WINDOW_BLACK);
		this.setWidth(ComponentsSize.WORKDAY_WINDOW_WIDTH);
		this.setHeight(ComponentsSize.WORKDAY_WINDOW_HEIGHT);
		this.setClosable(false);
		this.setResizable(false);
		this.setDraggable(true);
		this.center();

		createContent();
	}

	private Button save = null;
	private Button close = null;
	private WorkDayForm workDayForm = null;

	private void createContent()
	{
		save = new Button(Messages.get("save"));
		close = new Button(Messages.get("close"));
		workDayForm = new WorkDayForm(workDay);
		 
		close.addClickListener(controller);
		save.addClickListener(controller);
		close.setWidth("80px");
		save.setWidth("80px");
		
		// przyciski
		HorizontalLayout buttonsLayout = new HorizontalLayout();
		buttonsLayout.addComponent(save);
		buttonsLayout.addComponent(close);
		buttonsLayout.setSpacing(true);
		
		VerticalLayout windowLayout = new VerticalLayout();
		windowLayout.setMargin(true);
		windowLayout.setSpacing(true);
		windowLayout.setSizeFull();
		windowLayout.addComponent(workDayForm);
		windowLayout.setExpandRatio(workDayForm, 3.0f);
		windowLayout.addComponent(buttonsLayout);
		windowLayout.setComponentAlignment(buttonsLayout, new Alignment(Bits.ALIGNMENT_HORIZONTAL_CENTER));
		this.setContent(windowLayout);
	}
	
	@Override
	public Controller getController()
	{
		return controller;
	}
	
	public Button getSaveButton() {
		return save;
	}
	
	public Button getCloseButton() {
		return close;
	}
	
	public WorkDayForm getForm(){
		return workDayForm;
	}
	
	public WorkDay getFormBean() {
		return workDay;
	}
}
